<template>
  <div>
    <publicPageVue :json-obj="pageSetting" name="DataSourceConfig" :tables="tables" />
  </div>
</template>

<script>
  import { Mixin } from '@/common/minxin/Mixin'
  import { GFCD } from '@/utils/utils'
  import publicPageVue from '../../components/publicPage.vue'
  import { getList } from '../../api/home.js'
  import DataSourceConfig from '../../components/json/DataSourceConfig'
  export default {
    name: 'DataSourceConfig',
    components: { publicPageVue },
    mixins: [Mixin],
    data() {
      return {
        tables: {
          tableList: [],
          count: 0,
          pageSize: 50,
          limit: 1,
          name: 'DataSourceConfig',
          width: '150',
          operation: false,
          isNew: true,
          isRefresh: true,
          isRedis: true,
        },
        pageSetting: {
          search: {
            form: {
              field: [],
            },
          },
        },
      }
    },
    created() {
      this.init()
    },
    methods: {
      async init() {
        this.configSetting = GFCD('dams')
        let DBTypeData = await this.getDBTypeData()
        let DBRoleData = await this.getDBRoleData()
        let DBTypelist = []
        let DBRolelist = []
        DBTypeData.forEach((item) => {
          DBTypelist.push({ CODE: item.CONSTANT_NAME, LABEL: item.CONSTANT_NAME })
        })
        DBRoleData.forEach((item) => {
          DBRolelist.push({ CODE: item.CONSTANT_NAME, LABEL: item.CONSTANT_NAME })
        })
        // this.nowJsonData().then((data) => {
        this.pageSetting = DataSourceConfig
        let dialoglistField = this.pageSetting.DataSourceConfig.dialog.form.field
        dialoglistField.forEach((item) => {
          if (item.name == 'DB_TYPE') {
            item.options = DBTypelist
          }
          if (item.name == 'DB_ROLE') {
            item.options = DBRolelist
          }
        })
        // })
      },
      //获取数据库角色下拉数据
      async getDBRoleData() {
        let method = 'dams.data.source.conf.db.role.query'
        let res = await getList(`${this.configSetting.domain}${this.configSetting.baseUrl}`, {
          method: method,
          data: JSON.stringify({ '#LIMIT#': 1, '#PAGE_SIZE#': 9999 }),
        })
        return res.data['dams.data.source.conf.db.role.query'].data
      },
      //获取数据库类型下拉数据
      async getDBTypeData() {
        let method = 'dams.data.source.conf.db.type.query'
        let res = await getList(`${this.configSetting.domain}${this.configSetting.baseUrl}`, {
          method: method,
          data: JSON.stringify({ '#LIMIT#': 1, '#PAGE_SIZE#': 9999 }),
        })
        return res.data['dams.data.source.conf.db.type.query'].data
      },
    },
  }
</script>

<style lang="scss" scoped></style>
